import request from "@/utils/request";
import type {AjaxResult,page} from "@/utils/request"
const base = '/base/judge'


/**
 * 获取列表
 * @returns Promise
 */
export const getJudgeList = (data : JudgeReqDTO,param?: page) : Promise<AjaxResult> => {
    return request({
        url: `${base}/list`,
        method: 'post',
        params: param,
        data:data
    })
}
/**
 * 获取判题详情
 * @returns Promise
 */
export const getJudgeDetail = (id) : Promise<AjaxResult> => {
    return request({
        url: `${base}/${id}`,
        method: 'get',
    })
}

/**
 * 获取标签
 * @returns Promise
 */
export const submitTest = (data : TestJudgeDTO) : Promise<AjaxResult<string>> => {
    return request({
        url: `${base}/submit-problem-test-judge`,
        method: 'post',
        data:data
    })
}

/**
 * 获取排行榜
 * @returns Promise
 */
export const getRanks = (params) : Promise<AjaxResult> => {
    return request({
        url: `${base}/getRanks`,
        method: 'get',
        params : params
    })
}

/**
 *
 * @returns Promise
 */
export const submitProblemJudge = (data : SubmitJudgeDTO) : Promise<AjaxResult<JudgeResult>> => {
    return request({
        url: `${base}/submit-problem-judge`,
        method: 'post',
        data:data
    })
}

export const getTestJudgeResult = (param) : Promise<AjaxResult<RunResult>> => {
    return request({
        url: `${base}/get-test-judge-result`,
        method: 'get',
        params:param
    })
}

export const getJudgeProblemResult = (param) : Promise<AjaxResult<JudgeResult>> => {
    return request({
        url: `${base}/get-submission-detail`,
        method: 'get',
        params:param
    })
}



export type RunResult = {
    //输入
    testCaseInput?:string,
    //预期输出
    expectedOutput?:string,
    //实际输出
    file? : string,
    status: number,
    memory?: number,
    runTime?: number
    time?: number,
    msg?: string
}

export type JudgeResult = {
    id: string,
    pid: string,
    submitTime: any,
    status: number,
    share:number,
    errorMessage:string
    time?: number,
    memory?: number,
    score?:number,
    length:number,
    code: string,
    language: string
}


export type TestJudgeDTO = {
    code: string,
    language : string,
    testCaseInput : any
    expectedOutput: any
}
export type SubmitJudgeDTO = {
    pid: string,
    language: string,
    code: string,
}

export type JudgeReqDTO = {
  problemCode?:string;
  problemId?:string;
  status?:number;
  myOwn?:number;
  language?:string;
  nickName?:string;
  cid?:string;
}
